package com.bestcem.xm.deliver.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum DeliverTtypeEnum {

    DELIVER_TTYPE_SMS(0, "短信"),

    DELIVER_TTYPE_WECHAT(1, "微信推送"),

    DELIVER_TTYPE_ALIPAY(2, "支付宝推送"),

    DELIVER_TTYPE_REGION(3, "层级"),

    DELIVER_TTYPE_WECHAT_TIMING(4, "微信定时"),

    DELIVER_TTYPE_ALIPAY_TIMING(5, "支付宝定时"),

    DELIVER_TTYPE_EMAIL(6, "邮件投放"),

    DELIVER_TTYPE_CUSTOM(7, "定制投放"),

    DELIVER_TTYPE_DEFAULT(8, "默认投放"),

    DELIVER_TTYPE_EMBED(9, "嵌入投放"),

    DELIVER_TTYPE_DEFAULT_STORE(10, "默认投放-门店"),

    DELIVER_TTYPE_DEDICATED(11, "专用连接"),

    DELIVER_TTYPE_SAMPLE(12, "样本投放"),

    DELIVER_TTYPE_CUSTOM_LINK(13, "自定义链接"),

    DELIVER_TTYPE_CUSTOM_API(14, "接口投放"),

    DELIVER_TTYPE_WECHATMP(15, "微信公众号投放"),

    DELIVER_TTYPE_WECHATMINI(16, "微信小程序投放");

    @EnumValue
    private final int value;

    private final String desc;

    public static String getDescByValue(int value) {
        List<DeliverTtypeEnum> collect = Arrays.stream(DeliverTtypeEnum.values()).filter(one -> one.getValue() == value)
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(collect)) {
            return "";
        } else {
            return Objects.requireNonNull(collect.stream().findFirst().orElse(null)).getDesc();
        }
    }

    public static DeliverTtypeEnum getEnumByLambda(int value) {
        return Arrays.stream(DeliverTtypeEnum.values()).filter(e -> e.getValue() == value).findFirst().orElse(null);
    }
}
